package com.mby.utils;

import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by developer_01 on 2018/5/23.
 */
@Service
public class UserUtil {

    private static Set<String> forbidNames = new HashSet<>();
    private static Set<String> forbidIds = new HashSet<>();
    private static Set<String> legalNames = new HashSet<>();
    private static Set<String> legalIds = new HashSet<>();

    static {
        String[] names = {"销售顾问","试车员","售后检验员","领料员","售前检验员","保险专员","续保专员","定保专员","装潢专员","回访专员","电销顾问","销售经理","财务经理"};
        String[] ids = {"10061001","10061002","10061016","10061005","10061006","10061007","10061008","10061009","10061010","10061011","10061012","10061013","10061014"};
        for(int i=0;i<names.length;i++){
            forbidNames.add(names[i]);
        }
        for(int i=0;i<ids.length;i++){
            forbidIds.add(ids[i]);
        }
    }

    public static String filterRoleNames(String roleName){
        legalNames.clear();
        //System.out.println("过滤前:"+roleName);
        String[] roleNames = roleName.split(",");
        for(int i=0;i<roleNames.length;i++){
            if(!forbidNames.contains(roleNames[i])){
                legalNames.add(roleNames[i]);
            }
        }
        roleName = "";
        for(String name : legalNames){
            roleName = roleName + name + ",";
        }
        if(roleName.length() > 0){roleName = roleName.substring(0,roleName.length()-1);}
        //System.out.println("过滤后:"+roleName);
        return roleName;
    }

    public static String filterRoleIds(String roleId){
        legalIds.clear();
        //System.out.println("过滤前:"+roleId);
        String[] roleIds = roleId.split(",");
        for(int i=0;i<roleIds.length;i++){
            if(!forbidIds.contains(roleIds[i])){
                legalIds.add(roleIds[i]);
            }
        }
        roleId = "";
        for(String id : legalIds){
            roleId = roleId + id + ",";
        }
        if(roleId.length() > 0){roleId = roleId.substring(0,roleId.length()-1);}
        //System.out.println("过滤后:"+roleId);
        return roleId;
    }
}
